<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 header ("Content-Type:text/html; charset= utf-8");
 include_once dirname(__FILE__).'/include/conn.php';
 //header ("Content-Type:text/html; charset= utf-8");
 require_once ('config.php');
 
 

 
$pageNo = isset($_GET['page']) ? $_GET['page'] : 1 ; // current page = 1 
$pageSize = 4;
$sql = "SELECT * FROM guest_book ORDER BY id DESC ";

$sql .= " LIMIT " . ($pageNo - 1) * $pageSize . " , ". $pageSize;
$countResult = mysql_query("SELECT count(*) as totalCount FROM guest_book");
$countArray = mysql_fetch_array($countResult);
$pageTotalNum = ceil($countArray['totalCount']/$pageSize);

$result = mysql_query($sql);
if(!$result) exit('查询数据错误：'.mysql_error());
// 循环输出
while($gb_array = mysql_fetch_array($result)){
$guest_book[] = $gb_array;
}
if ($pageNo > 1) :
    $prePage = $pageNo - 1;
elseif ($pageNo == 1) :
    $prePage = $pageNo;
endif;

if ($pageTotalNum > $pageNo) :
    $nextPage = $pageNo + 1;
elseif($pageNo == $pageTotalNum):   
    $nextPage = $pageNo;
endif;

 $smarty->assign("title","留言板管理");
 $smarty->assign("pageTotalNum","$pageTotalNum");
 $smarty->assign("page","$pageNo");
 $smarty->assign("guest_books",$guest_book);
 $smarty->assign("prePage","$prePage");
 $smarty->assign("nextPage","$nextPage");
 $smarty->display("guest_book_look.html",md5("guest_book_admin.php"));
 
 ?>